<%@CODEPAGE=65001%>
<!--#include file="conn.asp"-->
<!doctype html>
<meta charset="utf-8">
<%
'Sub UploadForAspUpload()
	Set Jpeg = Server.CreateObject("persits.Jpeg")
	Set Upload = Server.CreateObject("Persits.Upload")
	Upload.CodePage = 65001
	Upload.regkey = "79385-70221-08938"
	Jpeg.regkey = "48958-77556-02411"
	MaxFileSize = 3072
	Path = SitePath&PhotoFolder
	Upload.SetMaxSize MaxFileSize*1024, True
	Upload.CreateDirectory Server.MapPath(SitePath&PhotoFolder&"thumb"), True
	'response.write Err.Number
	Upload.Save
	
	If Err.Number = 8 Then Call Result(0,"只允许上传小于"&MaxFileSize/1024&"M的文件")
	'Set File = Upload.Files("FILE1")
	For Each File in Upload.Files
		Jpeg.OpenBinary(File.Binary)
		Jpeg.PreserveAspectRatio = True
		Jpeg.Quality = 75
		Jpeg.Sharpen 1,120
		Randomize : ranNum=int(900*rnd)+100
		FileName = year(now)&month(now)&day(now)&hour(now)&minute(now)&Second(now)&ranNum&LCase(File.Ext)
		If CLng(Jpeg.OriginalWidth) > CLng(MaxWidth) then	
			'大于图片最大宽度的，先缩小
			If Jpeg.OriginalWidth > Jpeg.OriginalHeight Then
				Jpeg.Width = MaxWidth
			Else
				Jpeg.Height = MaxHeight
			End If
			Jpeg.save Server.MapPath(SitePath&PhotoFolder&FileName)
			'然后再生成缩略图
			If Jpeg.OriginalWidth > Jpeg.OriginalHeight Then
				Jpeg.Width = ThumbWidth
			Else
				Jpeg.Height = ThumbHeight
			End If
			Jpeg.save Server.MapPath(SitePath&PhotoFolder&"thumb/"&FileName)
		ElseIf CLng(Jpeg.OriginalWidth) > CLng(ThumbWidth) And CLng(Jpeg.OriginalWidth) < CLng(MaxWidth) Then
			File.Saveas Server.MapPath(SitePath&PhotoFolder&FileName)
			Jpeg.Width = ThumbWidth
			Jpeg.Height = (Jpeg.Originalheight/Jpeg.OriginalWidth)*ThumbWidth
			Jpeg.save Server.MapPath(SitePath&PhotoFolder&"thumb/"&FileName)
		End If
	Next
	Call Result(1,SitePath&PhotoFolder&"thumb/"&FileName)
	Set Jpeg = Nothing : Set Upload = Nothing
'End Sub
Sub Result(ErrNum,Str)
	Response.write "<script>parent.ajaxCallback("&ErrNum&",'"&Str&"')</script>"
	Response.end
End Sub
%>